---
title: "Plotly - New York NOAA Data"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
theme: spacelab
---
```{r setup, include = FALSE}
library(flexdashboard)
library(plotly)
library(tidyverse)
library(dplyr)
library(p8105.datasets)
```
```{r}
ny_noaa_data = ny_noaa %>%
janitor::clean_names() %>%
separate(col = date, into = c('year', 'month','day'), sep = '-') %>%
mutate(
year = as.numeric(year),
month = as.numeric(month),
day = as.numeric(day),
prcp = prcp/10,
tmax = as.numeric(tmax) / 10,
tmin = as.numeric(tmin) / 10)
```
{data-width=500}
-----------------------------------------------------------------------
### __Monthly Snow Depth in NYC in 2006 - Boxplot__
```{r}
ny_noaa_data %>%
select(id, year, month, snwd) %>%
group_by(month) %>%
drop_na(snwd) %>%
filter(year == 2006, snwd > 0) %>%
mutate(month = recode(month,
'1' = 'January',
'2' = 'February',
'3' = 'March',
'4' = 'April',
'5' = 'May',
'6' = 'June',
'7' = 'July',
'8' = 'August',
'9' = 'September',
'10' = 'October',
'11' = 'November',
'12' = 'December')) %>%
plot_ly(
x = ~snwd, y = ~month, color = ~month, type = "box") %>%
layout(
xaxis = list(title = "<b> Snow Depth (mm) </b>"),
yaxis = list(title = "<b> Month </b>",
categoryorder = "array ascending",
categoryarray = c("December", "November","October", "September", "August", "July", "June", "May", "April", "March", "February", "January")),
showlegend = FALSE)
```
{data-width=500}
-----------------------------------------------------------------------
### __Total Monthly Precipitation in NYC in 2006 - Barchart__
```{r}
ny_noaa_data %>%
select(id, year, month, prcp) %>%
group_by(month) %>%
drop_na(prcp) %>%
filter(year == 2006) %>%
mutate(month = recode(month,
'1' = 'January',
'2' = 'February',
'3' = 'March',
'4' = 'April',
'5' = 'May',
'6' = 'June',
'7' = 'July',
'8' = 'August',
'9' = 'September',
'10' = 'October',
'11' = 'November',
'12' = 'December')) %>%
plot_ly(
x = ~month, y = ~prcp, color = ~month, type = "bar") %>%
layout(
xaxis = list(title = "<b> Month </b>",
categoryorder = "array",
categoryarray = ~month),
yaxis = list(title = "<b> Precipitation (mm) </b>"),
showlegend = FALSE)
```
### __Average Maximum & Minimum Temperatures (C) in January - Scatterplot__
```{r}
ny_noaa_data %>%
select(id, year, month, tmax, tmin) %>%
group_by(year) %>%
drop_na(tmax, tmin) %>%
filter(month == 1) %>%
mutate(month = recode(month,
'1' = 'January'),
mean_tmax = mean(tmax),
mean_tmin = mean(tmin)) %>%
select(-tmin, -tmax) %>%
pivot_longer(
mean_tmax:mean_tmin,
names_to = "temp_observation",
values_to = "temp_measurement") %>%
mutate(temp_observation = recode(temp_observation,
'mean_tmax' = "Average Max Temperature",
'mean_tmin' = "Average Min Temperature")) %>%
plot_ly(
x = ~year, y = ~temp_measurement, color = ~temp_observation,
type = 'scatter', mode = 'markers') %>%
layout(
xaxis = list(title = "<b> Year </b>"),
yaxis = list(title = "<b> Temperature (C) </b>"),
legend = list(title = list(text = "<b> Temperature Observation </b>")))
```